package com.gewu.pm.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.bean.ReportCategoryBean;
import com.gewu.pm.bean.ReportItemBean;
import com.gewu.pm.ui.activity.home.ReportClockInActivity;
import com.gewu.pm.ui.activity.home.ReportCustomerVisitActivity;
import com.gewu.pm.ui.activity.home.ReportDailyActivity;
import com.gewu.pm.ui.activity.home.ReportDistributorSalesActivity;
import com.gewu.pm.ui.activity.home.ReportFreezerStatisticsActivity;
import com.gewu.pm.ui.activity.home.ReportGoodsSalesActivity;
import com.gewu.pm.ui.activity.home.ReportNoOrderCustomerActivity;
import com.gewu.pm.ui.activity.home.ReportOrderSummaryActivity;
import com.gewu.pm.ui.activity.home.ReportReducedOrderActivity;
import com.gewu.pm.ui.activity.home.ReportStoreActivity;
import com.gewu.pm.ui.activity.home.ReportTerminalReceivableActivity;
import com.gewu.pm.ui.activity.home.ReportTerminalSalesActivity;
import com.gewu.pm.ui.adapter.ReportCategoryAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 更多数据报表页面
 */
public final class MoreReportActivity extends AppActivity implements ReportCategoryAdapter.OnReportItemClickListener{

    private RecyclerView rvReportCategories;
    private ReportCategoryAdapter categoryAdapter;

    /** 报表分类列表 */
    private List<ReportCategoryBean> categoryList = new ArrayList<>();

    public static void start(Context context) {
        Intent intent = new Intent(context, MoreReportActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.more_report_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rvReportCategories = findViewById(R.id.rv_report_categories);

        // 设置线性布局
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        rvReportCategories.setLayoutManager(layoutManager);

        categoryAdapter = new ReportCategoryAdapter(this);
        // 设置报表项点击事件
        categoryAdapter.setOnReportItemClickListener(this);
        rvReportCategories.setAdapter(categoryAdapter);
    }

    @Override
    protected void initData() {
        // 初始化模拟数据
        initReportData();
    }

    /**
     * 初始化报表数据
     */
    private void initReportData() {
        // 客户报表
        List<ReportItemBean> customerReports = new ArrayList<>();
        customerReports.add(new ReportItemBean("1", "末下单客户报表", "掌控团队整体进度", R.mipmap.report_unordered_customer_ic));
        customerReports.add(new ReportItemBean("2", "终端应收报表", "终端报表记录", R.mipmap.report_terminal_receivable_ic));
        categoryList.add(new ReportCategoryBean("客户报表", customerReports));

        // 销售报表
        List<ReportItemBean> salesReports = new ArrayList<>();
        salesReports.add(new ReportItemBean("3", "订单汇总报表", "查看团队全部订单", R.mipmap.report_order_summary_ic));
        salesReports.add(new ReportItemBean("4", "配送商销售报表", "分析最新销售情况", R.mipmap.report_distributor_sales_ic));
        salesReports.add(new ReportItemBean("5", "终端销售报表", "终端销售分析报告", R.mipmap.report_terminal_sales_ic));
        salesReports.add(new ReportItemBean("6", "商品销售报表", "解析商品趋势", R.mipmap.report_product_sales_ic));
        salesReports.add(new ReportItemBean("7", "减货订单报表", "减货分析报告", R.mipmap.report_reduce_order_ic));
        salesReports.add(new ReportItemBean("8", "买赠-门店报表", "查看促销活动情况", R.mipmap.report_promotion_store_ic));
        categoryList.add(new ReportCategoryBean("销售报表", salesReports));

        // 销售报表（第二组）
        List<ReportItemBean> salesReports2 = new ArrayList<>();
        salesReports2.add(new ReportItemBean("9", "拜访报表", "团队活动事统计", R.mipmap.report_visit_ic));
        salesReports2.add(new ReportItemBean("10", "打卡报表", "考勤明细查询", R.mipmap.report_attendance_ic));
        salesReports2.add(new ReportItemBean("11", "日报报表", "了解团队日报汇总", R.mipmap.report_daily_ic));
        salesReports2.add(new ReportItemBean("12", "冰柜统计报表", "汇总冰柜补贴数据", R.mipmap.report_freezer_ic));
        categoryList.add(new ReportCategoryBean("销售报表", salesReports2));

        // 刷新数据
        categoryAdapter.setData(categoryList);
    }

    @Override
    public void onReportItemClick(ReportItemBean item) {
        String id = item.getId();
        switch (id) {
            case "1": //末下单客户报表
                startActivity(ReportNoOrderCustomerActivity.class);

                break;
            case "2": //终端应收报表
                startActivity(ReportTerminalReceivableActivity.class);

                break;
            case "3": //订单汇总报表
                startActivity(ReportOrderSummaryActivity.class);

                break;
            case "4": //配送商销售报表
                startActivity(ReportDistributorSalesActivity.class);

                break;
            case "5": //终端销售报表
                startActivity(ReportTerminalSalesActivity.class);

                break;
            case "6": //商品销售报表
                startActivity(ReportGoodsSalesActivity.class);

                break;
            case "7": //减货订单报表
                startActivity(ReportReducedOrderActivity.class);

                break;
            case "8": //买赠-门店报表
                startActivity(ReportStoreActivity.class);

                break;
            case "9": //拜访报表
                startActivity(ReportCustomerVisitActivity.class);

                break;
            case "10": //打卡报表
                startActivity(ReportClockInActivity.class);

                break;
            case "11": //日报报表
                startActivity(ReportDailyActivity.class);

                break;
            case "12": //冰柜统计报表
                startActivity(ReportFreezerStatisticsActivity.class);

                break;
        }
    }
}

